"""
异常相关知识
"""

try:
    f = open('test.txt','r',encoding='utf-8')
except :
    print("文件打开异常！")

# 指定异常
try:
    print(name)
except NameError:
    print("出现异常了")

# 捕获多个异常
try:
    1/0
    print(name)
except (NameError,ZeroDivisionError) as e:
    print(e)

# 异常else写法
try:
    print("hello")
except Exception as e:
    print("出现异常了")
else:
    print("没有任何异常发生")

# 异常finally
try:
    f = open('test.txt','r',encoding='utf-8')
except Exception as e:
    f = open('test.txt','w',encoding='utf-8')
else:
    print("没有任何异常发生")
finally:
    f.close()